﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Domain.Transactions;
using NHibernate;

namespace Common.Infrastructure.Persistence.Transactions
{
    //todo: exc handling
    public class TransactionExecutor : ITransactionExecutor
    {
        private readonly ISession _session;
        private ITransaction _transaction;

        public TransactionExecutor(ISession session)
        {
            _session = session;
        }


        public void StartTransaction()
        {
            if (_session.Transaction != null)
                 _transaction = _session.BeginTransaction();
        }

        public void Dispose()
        {
            _transaction.Dispose();
        }


        public void Rollback()
        {
            _transaction.Rollback();
        }

        public void Commit()
        {
            _transaction.Commit();
        }
    }
}
